#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ExpatImpl.h"
#include "MyXml.h"

bool ParseSomeXML (LPCSTR pszFileName)
{
    CMyXML sParser;
    if (!sParser.Create ())
        return false;
    
    // Open the file
    
    FILE *fp = fopen (pszFileName, "r");
    if (fp == NULL)
        return false;
    
    // Loop while there is data
    
    bool fSuccess = true;
    while (!feof (fp) && fSuccess)
    {
        LPSTR pszBuffer = (LPSTR) sParser.GetBuffer (256); // REQUEST
        if (pszBuffer == NULL)
            fSuccess = false;
        else
        {
            int nLength = fread (pszBuffer, 1, 256, fp); // READ
            fSuccess = sParser.ParseBuffer (nLength, nLength == 0); // PARSE
        }   
    }

    // Close the file
    
    fclose (fp);
    return fSuccess;

}

int main(int argc, char *argv[])
{
	if(argc > 1) {
		ParseSomeXML(argv[1]);
	} else {
		printf("Usage %s <XmlFileName>\n", argv[0]);	
	}
	return 0;
}
